//
// Created by delin10 on 2020/5/4.
//
#include <stdio.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "bits/socket.h"
#include "memory.h"
#include "net_utils.h"
#include "../debug.h"

struct sockaddr_in * to_ip_sockaddr_in(const char *ip, int port) {
    struct sockaddr_in *addr;
    addr = (struct sockaddr_in *)malloc(sizeof(struct sockaddr_in));
    memset(addr, 0, sizeof(struct sockaddr_in));
    addr->sin_family = AF_INET;
    addr->sin_port = htons(port);
    if (inet_aton(ip, &(addr->sin_addr)) < 0){
        d_log_err("Failed to translate ip = %s, port = %d", ip, port);
        return NULL;
    }
    return addr;
}
